﻿/**
* 命名空间: ICS_ViewModel
*
* 功 能： N/A
* 类 名： ComponentBase
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2021/9/17 15:00:50 小柚子爱学习 初版
*
* Copyright (c) 2021 Lir Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为个人机密信息，未经本人书面同意禁止向第三方披露．　│
*│　版权所有：Vip_Future 　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using ICS_Equipment.Components;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace ICS_Equipment.Components
{
    public class ComponentBase : UserControl
    {

        private bool _isSelected;
        //激活状态
        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                _isSelected = value;
                VisualStateManager.GoToState(this, value ? "RunState" : "UnselectedStte", false);

            }
        }

        //激活状态
        public bool IsRunning
        {
            get { return (bool)GetValue(IsRunningProperty); }
            set { SetValue(IsRunningProperty, value); }

        }
        public static readonly DependencyProperty IsRunningProperty =
                DependencyProperty.Register("IsRunning", typeof(bool), typeof(ComponentBase), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnRunningStateChanged)));

        public static void OnRunningStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            bool state = (bool)e.NewValue;
            VisualStateManager.GoToState(d as ComponentBase, state ? "SelectedState" : "UnselectedStte", false);

        }


        public bool IsFault
        {
            get { return (bool)GetValue(IsFaultProperty); }
            set { SetValue(IsFaultProperty, value); }
        }

        // Using a DependencyProperty as the backing store for IsFault.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsFaultProperty =
            DependencyProperty.Register("IsFault", typeof(bool), typeof(ComponentBase), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnFaultStateChanged)));
        public static void OnFaultStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            VisualStateManager.GoToState(d as ComponentBase, (bool)e.NewValue ? "SelectedState" : "UnselectedStte", false);

        }


        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Command.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(ComponentBase), new PropertyMetadata(default(ICommand)));



        public object CommandParameter
        {
            get { return (object)GetValue(CommandParametrProperty); }
            set { SetValue(CommandParametrProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandParametr.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandParametrProperty =
            DependencyProperty.Register("CommandParametr", typeof(object), typeof(ComponentBase), new PropertyMetadata(default(object)));




        private void ComponentBase_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //this.IsSelected = !this.IsSelected;
            //this.Command?.Execute(this.CommandParameter);
            //e.Handled = true;
        }
        public ComponentBase()
        {
            this.PreviewMouseLeftButtonDown += ComponentBase_PreviewMouseLeftButtonDown;
        }
    }

}

